package demo1.service.impl;

import demo1.dao_mb.ProductDao;
import demo1.entity.Product;
import demo1.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    ProductDao dao;

    @Transactional(rollbackFor = Exception.class)
    public void addProducts(List<Product> list) {
        for(Product p:list){
            dao.insertProduct(p);
            //throw new RuntimeException("我活够了！");
        }
    }

    @Override
    public void queryProduct(String name) {
        System.out.println(name+"产品信息为："+dao.selectByName(name));
    }
}
